from rest_framework.generics import ListAPIView
from rest_framework_extensions.cache.mixins import ListCacheResponseMixin

from .models import MyInfo
from .serializers import MyInfoViewSerializer


class MyInfoView(ListCacheResponseMixin, ListAPIView):
    ''' 个人信息 '''
    queryset = MyInfo.objects.all()
    serializer_class = MyInfoViewSerializer

    # 重写父类方法，添加缓存响应头
    def list(self, request, *args, **kwargs):
        response = super().list(request, *args, **kwargs)
        response['Cache-Control'] = 'max-age=180'
        return response
